<template>
	<view>
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="加载中"></u-loading-page>
		<view v-if="!loadding" class="main">
			<view class="top">
				<view class="title bottom-line">
					<u-icon color="#2979ff" size="18" name="grid"></u-icon>
					<text>{{data.name}}</text>
				</view>
				<view class="sn bottom-line">
					<u-icon color="#2979ff" size="18" name="tags"></u-icon>
					<text>{{sn}}</text>
				</view>
				<view class="name">
					<u-icon color="#2979ff" size="18" name="account"></u-icon>
					<text>{{name}}</text>
				</view>
			</view>
			<view v-for="(item,index) in data.rate_type_list" :key="index" v-if="item.is_show == 2" class="item">
				<view class="left">
					<u--text :text="item.title"></u--text>
				</view>
				<view v-if="item.cnno == 'ccardFee'" class="right">
					<!-- <u--input border="bottom" inputAlign="right" v-model="dats[item.cnno]" fontSize="13"
						clearable></u--input> -->
					<u-number-box button-size="24" step="0.01" decimal-length="2" min="0.53" max="0.6" v-model="dats[item.cnno]"></u-number-box>
				</view>
				<view v-else-if="item.cnno == 'quicFee'" class="right">
					<u-number-box button-size="24" step="0.5" min="0" max="3" decimal-length="1" v-model="dats[item.cnno]"></u-number-box>
				</view>
				<view v-else class="right">
					{{dats[item.cnno]}}
				</view>
			</view>
			<view class="saveBtn" @click="saveBtn">
				保 存
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadding: true,
				isFalse: true,
				data: [],
				userinfo: {},
				rate_setting_id: '',
				product_id: '',
				sn: '',
				name: '',
				dats: {}
			}
		},
		onLoad(e) {
			this.rate_setting_id = e.id
			this.sn = e.sn
			this.name = e.name
			this.userinfo = uni.getStorageSync('userinfo')
			this.loadData()
		},
		methods: {
			async loadData() {
				var that = this
				const {
					data: res
				} = await this.$myHttp({
					url: 'Terminal/getRateSettingDetail',
					data: {
						id: that.rate_setting_id,
						sn: that.sn
					},
					header: {
						'token': that.userinfo.token
					},
				});
				if (res.code == 1) {
					that.loadding = false
					this.data = res.data
					this.dats = res.data.rate_type_key
					this.product_id = res.data.id
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					setTimeout(function() {
						uni.navigateBack({
							delta: 1 // 返回的页面数，如果为1表示返回上一页
						});
					}, 1000)
				}
			},
			async saveBtn() {
				var that = this
				if (this.isFalse) {
					this.isFalse = false
					this.dats.sn = this.sn
					this.dats.mercId = this.data.merchant.mercId
					this.dats.product_id = this.product_id
					this.dats.agt_merc_id = this.data.merchant.agtMercId2_1
					const {
						data: res
					} = await this.$myHttp({
						url: 'Terminal/setRateUpdate',
						data: {
							param: this.dats
						},
						header: {
							'token': that.userinfo.token
						},
					});
					this.isFalse = true
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f3f4f6;
	}

	.main {
		.top {
			margin-bottom: 20rpx;
			background-color: #ffffff;
			padding: 30rpx 20rpx;
			font-size: 28rpx;

			.title {
				font-size: 32rpx;
				font-weight: bold;
				padding-bottom: 20rpx;
				display: flex;
				justify-content: flex-start;

				text {
					padding-left: 10rpx;
				}
			}

			.sn {
				font-weight: bold;
				padding: 20rpx 0;
				display: flex;
				justify-content: flex-start;

				text {
					padding-left: 10rpx;
				}
			}

			.name {
				color: #909399;
				padding-top: 20rpx;
				display: flex;
				justify-content: flex-start;

				text {
					padding-left: 10rpx;
				}
			}

			.bottom-line {
				border-bottom: 1px dashed #f4f4f5;
			}
		}

		.item {
			margin: 0 20rpx 20rpx 20rpx;
			background-color: #ffffff;
			border-radius: 10rpx;
			padding: 30rpx 20rpx;
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				justify-items: center;
			}

			.right {
				font-size: 26rpx;
				display: flex;
				justify-content: flex-end;
			}
		}

		.saveBtn {
			margin: 30rpx 20rpx 30rpx 20rpx;
			text-align: center;
			background-color: #2979ff;
			border-radius: 10rpx;
			padding: 30rpx 0;
			color: #ffffff;
			font-size: 32rpx;
		}
	}
</style>